﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyBiz.Core.BuildingParts;
using MyBiz.Core.Products;

namespace MyBiz.Core.Shops
{
    public abstract class IShop : IEntity
    {
        private FinanceBox _financeBox = new FinanceBox();
        private IStorage _storage;

        public FinanceBox Finance { get { return _financeBox; } }

        public IShop(IStorage storage = null)
        {
            _storage = storage ?? new MixStorage();
        }

        public IShop()
            :this(null)
        {
            
        }

        public bool BuyProduct(IProduct product)
        {
            var res = _financeBox.CheckIn(product);

            if (res)
                _storage.Add(product);

            return res;
        }

        public IProduct SellProduct(IProductCategory productCategory, int i)
        {
            var p = _storage.GetProduct(productCategory, i);

            if (!_financeBox.CheckOut(p))
            {
                _storage.Add(p);
                return null;
            }

            return p;
        }



        public string Id { get; private set; }
        public string Name { get; private set; }
    }
}
